"""
author: liuxu
date: 2025/5/30
description: 复测hipgdb相关的bug
"""
import os
import allure
import pytest

from common.logger_ctrl import mylogger
from common.ssh_command import exec_cmd, interactive_exec_cmd
from base_public.testbase import BasePublic
from setting import CPP_DIR


@pytest.mark.medium
@allure.feature('hipgdb相关bug')
class TestHipgdbBugCase(BasePublic):
    def test_bug_66835(self, test_env, dcu_info):  # 原bug在km/kme会复现
        """
        Bug链接: http://hpczentao.sugon.com/bug-view-66835.html
        标题: hipgdb调试kme rccl debug版本，在核函数打印堆栈信息后gdb崩溃
        问题描述: hipgdb问题
        :return:
        """
        # 判断环境，用例只在km、kme测试
        gfx_arch = dcu_info["gfx_arch"]
        if gfx_arch in ["gfx906"]:
            pytest.skip(f"Tesecase not supported on this DCU ({gfx_arch}) platform")
        # 编译用例
        src_case_dir = os.path.join(CPP_DIR, "bug_case/bug-66835")
        des_exe_name = self.compile_source_code(
            src_file_name=f"{os.path.join(src_case_dir, '2dshfl.cpp')} {os.path.join(src_case_dir, 'lib.cpp')}",
            des_exe_name="2dshfl", compile_paras="-g")

        # 执行hipgdb测试
        generator = interactive_exec_cmd(cwd=test_env)
        next(generator)
        for cmd in [f"HSA_FORCE_FINE_GRAIN_PCIE=1 hipgdb --args {des_exe_name}", "b run<int>", "y", "run", "bt", "quit", None]:
            info, err = generator.send((cmd, 1))
            print(info, err)



